package com.zwp.base.paging

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.paging.LoadState
import androidx.paging.LoadStateAdapter
import androidx.recyclerview.widget.RecyclerView
import com.zwp.base.R


class CommonFooterAdapter : LoadStateAdapter<CommonFooterAdapter.FooterViewHolder>() {


    var retry : (() -> Unit)? = null

    override fun onBindViewHolder(holder: FooterViewHolder, loadState: LoadState) {
    }

    override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): FooterViewHolder {
        val layoutId = when (loadState) {
            is LoadState.NotLoading -> {
                R.layout.footer_nothing_item
            }
            is LoadState.Error -> {
                R.layout.footer_error_item
            }
            is LoadState.Loading -> {
                R.layout.footer_loading_item
            }
            else -> {
                R.layout.footer_loading_item
            }
        }

        return DataBindingUtil.inflate<ViewDataBinding>(
            LayoutInflater.from(parent.context),
            layoutId,
            parent,
            false
        ).let {
            FooterViewHolder(it)
        }
    }

    class FooterViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root)
}